package com.saa.application.service;




import com.saa.application.dao.SaaApplicationDeploymentRequestDao;
import com.saa.application.po.SaaApplicationDeploymentRequest;
import com.saa.application.pojo.PageBean;
import com.saa.common.vo.OmsResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AppDeploymentRequestService {
    public static final Logger logger = LoggerFactory.getLogger(AppDeploymentRequestService.class);

    @Autowired
    private SaaApplicationDeploymentRequestDao saaApplicationDeploymentRequestDao;

    //增加应用申请
    public OmsResultVo insertAppDeploymentRequest(SaaApplicationDeploymentRequest saaApplicationDeploymentRequest) {
        int res = saaApplicationDeploymentRequestDao.insertSelective(saaApplicationDeploymentRequest);
        if(res!=0){
            return OmsResultVo.builder(200, "新增成功", null);
        }else {
            return OmsResultVo.builder(500, "新增失败", null);
        }
    }

    //查询应用申请分页
    public OmsResultVo getAppDeploymentRequestPage(SaaApplicationDeploymentRequest saaApplicationDeploymentRequest, Integer page, Integer pageSize) {
        int startIndex = (page - 1) * pageSize;
        Map<String, Object> params = new HashMap<>();
        params.put("startIndex",startIndex);
        params.put("pageSize",pageSize);
        params.put("saaApplicationDeploymentRequest",saaApplicationDeploymentRequest);
        List<SaaApplicationDeploymentRequest> appDeploymentRequestList = saaApplicationDeploymentRequestDao.selectPage(params);
        Long total = saaApplicationDeploymentRequestDao.selectTotal();
        if(appDeploymentRequestList!=null){
            PageBean pageBean = new PageBean();
            pageBean.setTotal(total);
            pageBean.setRows(appDeploymentRequestList);
            return OmsResultVo.builder(200, "查询成功", pageBean);
        }else {
            return OmsResultVo.builder(500, "查询失败", null);
        }
    }

    //查询应用申请
    public OmsResultVo getAppDeploymentRequest(SaaApplicationDeploymentRequest saaApplicationDeploymentRequest) {
        List<SaaApplicationDeploymentRequest> appDeploymentRequestList = saaApplicationDeploymentRequestDao.selectList(saaApplicationDeploymentRequest);
        if(appDeploymentRequestList!=null){
            return OmsResultVo.builder(200, "查询成功", appDeploymentRequestList);
        }else {
            return OmsResultVo.builder(500, "查询失败", null);
        }
    }

//    //删除应用申请

    public OmsResultVo deleteAppDeploymentRequest(SaaApplicationDeploymentRequest saaApplicationDeploymentRequest) {
        Integer id = saaApplicationDeploymentRequest.getApplicationId();
        int res = saaApplicationDeploymentRequestDao.deleteByPrimaryKey(id);
        if(res!=0){
            return OmsResultVo.builder(200, "删除成功", null);
        }else {
            return OmsResultVo.builder(500, "删除失败", null);
        }
    }
    //修改应用申请

    public OmsResultVo updateAppDeploymentRequest(SaaApplicationDeploymentRequest saaApplicationDeploymentRequest) {
        int res = saaApplicationDeploymentRequestDao.updateSelectiveByPrimaryKey(saaApplicationDeploymentRequest);
        if(res!=0){
            return OmsResultVo.builder(200, "更新成功", null);
        }else {
            return OmsResultVo.builder(500, "更新失败", null);
        }
    }
}
